/**
 * TmPackSerialImpl.java
 * Created at 2017-2-17
 * Created by xieshuang
 * Copyright (C) 2017 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.rms.basic.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.broadtext.common.exp.DaoException;
import com.broadtext.common.repository.EntityDao;
import com.broadtext.rms.basic.dao.ITmPackSerialDao;
import com.broadtext.rms.basic.model.TmPackSerial;

/**
 * <p>ClassName: TmPackSerialImpl</p>
 * <p>Description: 电池管理dao实现类</p>
 * <p>Author: xieshuang</p>
 * <p>Date: 2017-2-17</p>
 */
@Repository("tmPackSerialDao")
public class TmPackSerialDaoImpl extends EntityDao<TmPackSerial> implements ITmPackSerialDao {
    
    /**
     * 
     * <p>Description: 查询电池对应状态数量</p>
     * @param sql 查询语句
     * @param status 状态 0:未使用，1：已使用，2：已报废
     * @return 数量
     * @throws DaoException 异常
     */
    public long getStatusCount(String sql, String status) throws DaoException{
        return  this.getCurrentSession().selectOne(sql, status);
    }
    
    /**
     * 
     * <p>Description: 获取电池id列表</p>
     * @param queryParam 查询参数
     * @return 电池id列表
     * @throws DaoException 异常
     */
    @SuppressWarnings("unchecked")
    public List<TmPackSerial> getMaxId(String sql, String queryParam) throws DaoException {
        return super.findByProperty(sql, queryParam);
    }
    
    /**
     * 
     * <p>Description: 批量插入数据</p>
     * @param sql sqlId
     * @param newPackList 待插入数据
     * @throws DaoException 异常
     */
    public void insertBatch(String sql, List<TmPackSerial> newPackList) throws DaoException {
        this.getCurrentSession().insert(sql, newPackList);
    }
    
    /**
     * 
     * <p>Description: 检查待删除电池状态是否合法</p>
     * @param ids id数组
     * @return 检查结果
     * @throws DaoException 异常
     */
    public Object checkPackStatus(String[] ids) throws DaoException{
        String result = "";
        List<TmPackSerial> packList;
        packList = this.getCurrentSession().selectList("com.broadtext.rms.basic.model.TmPackSerial.getPackByIds",ids);
        if(packList.isEmpty()){
            //只包含未使用状态返回true;
            result = "true";
        } else {
            //待删除电池中包含其他状态返回false;
            result = "false";
        }
        return result;
    }

    /** (non-Javadoc)
     * <p>Title: checkRepeatPackCode</p>
     * <p>Description: </p>
     * @param packCode
     * @return
     * @throws DaoException
     * @see com.broadtext.rms.basic.dao.ITmPackSerialDao#checkRepeatPackCode(java.lang.String)
     */
    @Override
    public long checkRepeatPackCode(String packCode) throws DaoException {
        return  this.getCurrentSession().selectOne("com.broadtext.rms.basic.model.TmPackSerial.checkRepeatCode", packCode);
    }
    
    
}
